package com.gxa.insurance.service.impl;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.exception.ExceptionCode;
import com.gxa.insurance.mapper.SalaryMapper;
import com.gxa.insurance.pojo.Salary;
import com.gxa.insurance.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Min
 */
@Service
public class SalaryServiceImpl implements SalaryService {
    @Autowired
    private SalaryMapper salaryMapper;

    @Override
    public Integer insertSalaryMessage(Salary salary) throws BusinessException {

        if(salary==null){
            throw new BusinessException(ExceptionCode.WRONG_VALUE);
        }

       salary.setOverTime(new Date(System.currentTimeMillis()));


        Integer ARow=salaryMapper.insertSalaryMessage(salary);

        return ARow;
    }

    @Override
    public Map<String, Object> selectAllSalary(Integer page, Integer pageSize) {
        if(page<=0){
            page=1;
        }else{
            pageSize=10;
        }
        // 计算起始
        page=(page-1)*pageSize;

        // 进行查询
        List<Salary> salaryList=salaryMapper.selectAllByPage(page,pageSize);
        Integer count=salaryMapper.selectCount();
        Map<String,Object> map = new HashMap<>();
        map.put("list",salaryList);
        map.put("count",count);
        return map;
    }
}
